package com.ggh.jinjilive.ui.social.record.adapter;

import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;

import com.ggh.jinjilive.R;
import com.ggh.jinjilive.databinding.ItemVisitorsExamineBinding;
import com.ggh.jinjilive.listener.AddItemOnClickListener;
import com.ggh.jinjilive.mobile.social.visitors.VisitorsRecord;
import com.bumptech.glide.Glide;

import java.util.List;

public class ExamineAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private List<VisitorsRecord> visitorsRecordList;


    public void setAdd(List<VisitorsRecord> visitorsRecordList) {
        this.visitorsRecordList = visitorsRecordList;
        notifyDataSetChanged();
    }

    public void Add(List<VisitorsRecord> visitorsRecordList) {
        if(null != this.visitorsRecordList){
            this.visitorsRecordList.addAll(visitorsRecordList);
        }else {
            this.visitorsRecordList = visitorsRecordList;
        }
        notifyDataSetChanged();
    }


    private AddItemOnClickListener addItemOnClickListener;

    public void setAddItemOnClickListener(AddItemOnClickListener addItemOnClickListener) {
        this.addItemOnClickListener = addItemOnClickListener;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ItemVisitorsExamineBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.item_visitors_examine, parent, false);
        return new ItemViewHolder(binding);
    }

    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder recyclerViewholder,final int position) {
        if(recyclerViewholder instanceof ItemViewHolder){
            ItemViewHolder holder = (ItemViewHolder) recyclerViewholder;
            VisitorsRecord visitorsRecord = visitorsRecordList.get(position);
            if (null != visitorsRecord) {
                Glide.with(holder.binding.imgPortrait.getContext()).load(visitorsRecord.getHead_portrait()).into(holder.binding.imgPortrait);
                Glide.with(holder.binding.imgDressup.getContext()).load(visitorsRecord.getHead_frame()).into(holder.binding.imgDressup);
                holder.binding.nearbyRightItemName.setText(visitorsRecord.getNickname());
                holder.binding.nearbyRightItemTime.setText(visitorsRecord.getCreate_time());
            }
        }

    }

    @Override
    public int getItemCount() {
        return null == visitorsRecordList ? 0 : visitorsRecordList.size();
    }


    class ItemViewHolder extends RecyclerView.ViewHolder {
        ItemVisitorsExamineBinding binding;
        public ItemViewHolder(@NonNull ItemVisitorsExamineBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }

}